<template>
  <div>
    <page-list :x-uri="uri" :doactions="doactions" :checkbox-item="false">
      <!-- 自定义tab -->
      <template v-slot:page-tabs>
        <tabs />
      </template>
      <!-- 页面操作按钮 -->
      <template v-slot:page-button>
        <el-button v-auth="'school.level.create'" size="mini" type="primary" @click="create">新建等级</el-button>
      </template>
    </page-list>
  </div>
</template>

<script>
import PageList from '@public/template/page_list.vue';
import Tabs from '../tabs';
export default {
  components: {
    PageList,
    Tabs
  },
  inject: ['reload'],
  data() {
    return {
      uri: '/school/admin/level/list',
      doactions: [
        { title: '编辑', meta: { permission: 'school.level.edit' }, callback: this.edit },
        { title: '删除', meta: { permission: 'school.level.delete' }, callback: this.delete }
      ]
    };
  },
  methods: {
    create: function() {
      this.$router.push({ path: '/school/level/create' });
    },
    edit: function({ row }) {
      this.$router.push({ path: '/school/level/' + row.id + '/edit' });
    },
    delete: function({ row }) {
      this.$box
        .confirm('确认删除吗')
        .then(() => {
          this.$http.delete(
            '/school/admin/level/' + row.id,
            {},
            response => {
              this.$message.success(response.msg, _ => {
                this.reload();
              });
            },
            error => {
              this.$message.error(error.msg);
            }
          );
        })
        .catch(() => {});
    }
  }
};
</script>
